package com.laikan.reader.article.adapter;

import android.content.Context;
import android.net.Uri;
import android.support.v4.view.PagerAdapter;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;
import com.facebook.drawee.view.SimpleDraweeView;
import com.laikan.reader.R;
import com.laikan.reader.core.bean.BookFocusBean;

import java.util.ArrayList;

import static android.R.attr.banner;

/**
 * Created by hejunlin on 2016/8/25.
 */
public class BookFocusBannerAdapter extends PagerAdapter {

    private Context mContext;
    private float mImageCorner = -1F;
    private static final int DEFAULT_ITEM_NUM = 1;
    private ArrayList<BookFocusBean.Banner> bannerList;
/*    private int[] ResIds = new int[]{
        R.drawable.sign_in_topbg,
        R.drawable.sign_in_topbg,
        R.drawable.sign_in_topbg,
        R.drawable.sign_in_topbg,
        R.drawable.sign_in_topbg,
    };*/

    private BookFocusBannerAdapter.OnItemClickListener onItemClickListener;

/*    private String[] TextNames = new String[]{
        "第一本",
        "第二本",
        "第三本",
        "第四本"
    };*/

    public BookFocusBannerAdapter(Context content, ArrayList<BookFocusBean.Banner> banner) {
        this.mContext = content;
        this.bannerList = banner;
    }

    @Override
    public int getCount() {
        return bannerList.size();
    }

    @Override
    public boolean isViewFromObject(View view, Object object) {
        return view == object;
    }

    @Override
    public void destroyItem(ViewGroup view, int position, Object object) {
        view.removeView((View)object);
    }

    @Override
    public Object instantiateItem(ViewGroup container, int position) {
        View view = LayoutInflater.from(mContext.getApplicationContext()).inflate(R.layout.focus_recommend_page_item, container, false);
        if(bannerList != null && bannerList.get(position) != null){
            final BookFocusBean.Banner banner = bannerList.get(position);
            SimpleDraweeView iv_banner = (SimpleDraweeView)view.findViewById(R.id.iv_banner);
            TextView tv_image_desc = (TextView)view.findViewById(R.id.tv_image_desc);

            tv_image_desc.setVisibility(View.GONE);
            iv_banner.setImageURI(Uri.parse(banner.getImg()));

        }
            view.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View view) {
                    onItemClickListener.onItemClick(view, banner);
                }
            });

            container.addView(view);
        return view;
    }

    public void setOnItemClickListener(OnItemClickListener listener){
        this.onItemClickListener = listener;
    }

    public interface OnItemClickListener {

        void onItemClick(View view, Object data);
    }
}
